package com.hong.demo.other.easyrules;

import org.jeasy.rules.api.Facts;
import org.jeasy.rules.api.Rules;
import org.jeasy.rules.api.RulesEngine;
import org.jeasy.rules.core.DefaultRulesEngine;
import org.jeasy.rules.core.RulesEngineParameters;

public class TestRule {

    public static void main(String[] args) {
        // 只要匹配到第一条规则就跳过后面规则匹配
        RulesEngineParameters parameters = new RulesEngineParameters().skipOnFirstAppliedRule(true);
        RulesEngine rulesEngine = new DefaultRulesEngine(parameters);

        // 创建规则
        Rules rules = new Rules();
        rules.register(new EightRule());
        rules.register(new ThreeRule());
        rules.register(new RuleUnitGroup(new EightRule(), new ThreeRule()));
        rules.register(new OtherRule());

        Facts facts = new Facts();
        for (int i = 1; i <= 50; i++) {
            // 对应的 name 要和规则里面的 @Fact 一致
            facts.put("number", i);

            // 执行规则
            rulesEngine.fire(rules, facts);
        }
    }
}